# -*- coding: utf-8 -*-
"""
菜单模型 - 重构以匹配数据库表结构
"""

from sqlalchemy import Column, Integer, String, BigInteger, CHAR
from sqlalchemy.orm import relationship
from app.models.base import BaseModel


class Menu(BaseModel):
    """菜单权限表 - 匹配sys_menu表结构"""
    __tablename__ = "sys_menu"

    menu_id = Column(BigInteger, primary_key=True, comment="菜单ID")
    menu_name = Column(String(50), nullable=False, comment="菜单名称")
    parent_id = Column(BigInteger, default=0, comment="父菜单ID")
    order_num = Column(Integer, default=0, comment="显示顺序")
    path = Column(String(200), default='', comment="路由地址")
    component = Column(String(255), comment="组件路径")
    query_param = Column(String(255), comment="路由参数")
    is_frame = Column(Integer, default=1, comment="是否为外链（0是 1否）")
    is_cache = Column(Integer, default=0, comment="是否缓存（0缓存 1不缓存）")
    menu_type = Column(CHAR(1), default='', comment="菜单类型（M目录 C菜单 F按钮）")
    visible = Column(CHAR(1), default='0', comment="显示状态（0显示 1隐藏）")
    status = Column(CHAR(1), default='0', comment="菜单状态（0正常 1停用）")
    perms = Column(String(100), comment="权限标识")
    icon = Column(String(100), default='#', comment="菜单图标")

    # 关联关系
    roles = relationship("Role", secondary="sys_role_menu", back_populates="menus")

